/** Apple division the backtrack way */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[26];

ll mindiff, total;
int N;

void backtrack(int idx, ll sum) {
  if(idx==N) {
    ll diff = abs(total - 2*sum);
    mindiff = min(mindiff,diff);
    return;
  }
  else {
    backtrack(idx+1, sum);
    backtrack(idx+1, sum+arr[idx]);
  }
  return;
}

int solve() {
  cin>>N;
  for(int i=0;i<N;++i) {
    cin>>arr[i];
    total+=arr[i];
  }
  mindiff = total;
  backtrack(0,0);
  cout<<mindiff<<endl;
  return 0;
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  solve();
  return 0;
}